package com.pinganfu.mock.server;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server3 {
	private ServerSocket ss;
    private Socket s;
    private BufferedReader br;
    private PrintWriter pw;
    public Server3() {
        try {
                ss = new ServerSocket(8081);
                System.out.println("Server is starting...");
                	s = ss.accept();
	                br = new BufferedReader(new InputStreamReader(s.getInputStream()));
	                pw = new PrintWriter(s.getOutputStream(),true);
	                String line = br.readLine();
	                System.out.println(line);
	                
	                
	                
	                pw.println("<?xml version='1.0' encoding=\"GB2312\"?><Cartoon><Message id=\"0000000000009501\"><CPRes id=\"CPRes\"><version>1.1.0</version><instId>CIBCC</instId><serialNo>0000000000009501</serialNo><bankCardNo>4512891016948106</bankCardNo><overdraft>A</overdraft></CPRes><Signature><SignatureValue>DDF11790</SignatureValue></Signature></Message></Cartoon>");
	                //pw.println("helloworld");
	                br.close();
	                pw.close();
        } catch (IOException ie) {
            ie.printStackTrace();
        }
    }
    
    
    public void run() {
    	
    	
	}
    public void main(String[] args) throws Exception {
        //new Server3();
    	
    	try {
			ss = new ServerSocket(8081);
			System.out.println("服务器已经开启，等待连接。"); 
			  while (true) {  
				  s = ss.accept();
				  run();
			  }
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	
    }
}
